# -*- encoding: utf-8 -*-
"""
@author: CarpeDiem
@data: 22/9/16
@version: 0.1
@description: 穷举法算出可能的情况
"""
def split_number(number):
    number_list = []
    while number:
        number_list.append(number%10)
        number = number // 10
    return number_list

def count_number(count):
    count_list = [count for _ in range(10)]
    number = 0
    while True:
        flag = False
        number += 1
        number_list = split_number(number)
        for i in range(len(number_list)):
            if count_list[number_list[i]] == 0:
                flag = True
                break
            else:
                count_list[number_list[i]] -= 1
        if flag:
            break
    return (number - 1)
                
def main():
    print(count_number(2021))

if __name__ == "__main__":
    main()